package com.dpxm.zdbdg.charts.shuangseqiu.service;

import com.dpxm.zdbdg.charts.shuangseqiu.dao.KuaiLeBaDao;
import com.dpxm.zdbdg.charts.shuangseqiu.vo.KuaiLeBaSidan;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import vehiclebase.utils.ToolsUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

@Service
@Slf4j
public class KuaiLeBaSiDanAll {

    @Autowired
    private KuaiLeBaDao kuaiLeBaDao;
    static int cnt = 0;
    public  List<String> saveKuaiLeBaAll() {
        Stack<Integer> stack = new Stack<Integer>();
        List<String> list = new ArrayList<>(); //组合出来的四位数的集合
        /*1-80所有的数字*/
        List<Integer> nubmInteger = new ArrayList<>();
        for(int a=1 ; a<=80; a++){
            nubmInteger.add(a);
        }

        List<KuaiLeBaSidan> KuaiLeBaSidanList= new ArrayList<>();
        recursion3(nubmInteger, 0, 4, 0,cnt,stack,list,KuaiLeBaSidanList);
        //  System.out.println(cnt);
       //第一次存储所有的1-80四胆，已存表所以注释 kuaiLeBaDao.saveKuaiLeBaSiDanALL(KuaiLeBaSidanList);
        return list;
    }

    ///maxnum 标识位数（排列组合的下标）
    public  void recursion3(List<Integer> array, int curnum, int maxnum, int indexnum,
                            int cnt, Stack<Integer> stack, List<String> list, List<KuaiLeBaSidan> kuaiLeBaSidans ) {
        if (curnum == maxnum) {
            cnt++;
            //  System.out.println(stack);
            //  System.out.println("取数"+stack.get(0)+","+stack.get(1)+","+stack.get(2)+","+stack.get(3));
                KuaiLeBaSidan kuaiLeBaSidan = new KuaiLeBaSidan();
                list.add(stack.get(0)+","+stack.get(1)+","+stack.get(2)+","+stack.get(3));
                kuaiLeBaSidan.setNubm(stack.get(0)+","+stack.get(1)+","+stack.get(2)+","+stack.get(3));
                kuaiLeBaSidans.add(kuaiLeBaSidan);
            return;
        }
        for (int i = indexnum; i < array.size(); i++) {
            if (!stack.contains(array.get(i))) {
                stack.push(array.get(i));
                recursion3(array, curnum + 1, maxnum, i,cnt,stack,list,kuaiLeBaSidans);
                stack.pop();
            }
        }
    }

}
